package com.example.findmystuff;
//package com.database.findmystuff;

import com.database.findmystuff.*;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Calendar;

public class AddLostItemActivity extends Activity {
	
	Button lostSubmit, lostCancel;
	EditText lostName, lostCategory, lostDescription, lostLocation, lostContact;
	Toast toast;
	Calendar calendar = Calendar.getInstance();
	/**
	 * This method is called when the activity is created
	 * @param savedInstanceState a bundle used to save the state that this instance of the activity is in.
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_lost_item);
		
		
		//Variables for buttons
		lostSubmit = (Button) findViewById(R.id.submitButton);
        lostCancel = (Button) findViewById(R.id.cancelButton);
        
        //Variables for text fields
        lostName = (EditText) findViewById(R.id.nameText);
        lostCategory = (EditText) findViewById(R.id.losttypeText);
        lostDescription = (EditText) findViewById(R.id.lostdescriptionText);
        lostLocation = (EditText) findViewById(R.id.lostlocationText);
        lostContact = (EditText) findViewById(R.id.lostcontactText);
        
        
        lostSubmit.setOnClickListener(
        		new View.OnClickListener() {
        			@Override
					public void onClick(View v) {
        				Log.v("loginAttempt", "loggedUser: "+MainActivity.loggedUser);
        				Item item = new Item(lostName.getText().toString(), lostCategory.getText().toString(), lostDescription.getText().toString(),lostLocation.getText().toString() , lostContact.getText().toString(), "Lost",calendar.getTime().toString());
        				
        				MainActivity.database.createItem(MainActivity.database.getUser(MainActivity.loggedUser), item);
						toast = Toast.makeText(getApplicationContext(), "Success, " + lostDescription.getText().toString() + " added", Toast.LENGTH_SHORT);
						toast.setGravity(Gravity.TOP|Gravity.CENTER, 0, 70);
						toast.show();
						MainActivity.database.saveObject(MainActivity.database);
        				Intent i = new Intent(AddLostItemActivity.this, ListItemsActivity.class);
						startActivity(i);
        			}
        		});
        
        lostCancel.setOnClickListener(
        		new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent i = new Intent(AddLostItemActivity.this, ListItemsActivity.class);
						startActivity(i);
					}
				});
	}
	/**
	 * Initializes the contents of the Activity's standard options menu.
	 * @param menu the standard options menu
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_add_lost_item, menu);
		return true;
	}

}
